package com.edgar.fileupload.library;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by edgar on 2015/12/27.
 * 文件上传请求实体
 */
class UploadRequest{
    String url;
    List<File> uploadFiles;
    OnUploadListener listener;
    /**
     * 自定义head
     */
    Map<String,String> headerMap;

    public static UploadRequest createUploadRequest(String url,
                                                    List<File> uploadFiles, Map<String,String> headerMap,OnUploadListener listener){
        UploadRequest uploadRequest = new UploadRequest();
        uploadRequest.url = url;
        uploadRequest.uploadFiles = uploadFiles;
        uploadRequest.listener = listener;
        uploadRequest.headerMap = headerMap;
        return uploadRequest;
    }

    public void addHead(String key,String value){
        ensureHeaderMap();
        headerMap.put(key,value);
    }

    public void addHeadMap(Map<String,String> headerMap){
        ensureHeaderMap();
        headerMap.putAll(headerMap);
    }

    public Map<String,String> getHeaderMap(){
        return headerMap;
    }

    private void ensureHeaderMap(){
        if(headerMap == null){
            headerMap = new HashMap<String,String>();
        }
    }
}